'use strict';

const Service = require('egg').Service;

class StatisticsService extends Service {
  async getOverview() {
    const { ctx } = this;

    try {
      // 统计各项数据
      const [
        users,
        enterprises, 
        jobs, 
        applications,
        resumes,
        experiences,
        questions,
        schedules
      ] = await Promise.all([
        ctx.model.User.count(),
        ctx.model.Enterprise.count(),
        ctx.model.Job.count(),
        ctx.model.JobApplication.count(),
        ctx.model.Resume.count({ where: { status: 1 } }),
        ctx.model.InterviewExperience.count(),
        ctx.model.Question.count(),
        ctx.model.InterviewSchedule.count(),
      ]);

      return {
        users,
        enterprises,
        jobs,
        applications,
        resumes,
        experiences,
        questions,
        schedules
      };
    } catch (error) {
      ctx.logger.error('统计数据获取失败:', error);
      // 返回默认值
      return {
        users: 0,
        enterprises: 0,
        jobs: 0,
        applications: 0,
        resumes: 0,
        experiences: 0,
        questions: 0,
        schedules: 0
      };
    }
  }
}

module.exports = StatisticsService;


